package com.lywz.core.bean;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * spring bean 管理
 * 
 * @author Lionel pang
 * @date 2010-3-17
 */
public class SpringManager implements BeanFactory {
	// spring的上下文
	private ApplicationContext _context;

	public SpringManager(String configFilePath){
		_context = new ClassPathXmlApplicationContext(configFilePath);
	}
	
	public boolean containsBean(String name) {
		return _context.containsBean(name);
	}

	public boolean containsBeanDefinition(String beanName) {
		return _context.containsBeanDefinition(beanName);
	}

	public String[] getAliases(String name) {
		return _context.getAliases(name);
	}

	@SuppressWarnings("unchecked")
	public <T> T getBean(String name, Class<T> requiredType) throws BeansException {
		return (T) _context.getBean(name, requiredType);
	}

	@SuppressWarnings("unchecked")
	public <T> T getBean(String name, Object[] args) throws BeansException {
		return (T)_context.getBean(name, args);
	}

	@SuppressWarnings("unchecked")
	public <T> T getBean(String name) throws BeansException {
		return (T) _context.getBean(name);
	}

	public String getDisplayName() {
		return _context.getDisplayName();
	}
}
